<template>
  <input type="text" placeholder="请输入待办事项" @keyup.enter="add" v-model="text">
</template>

<script setup>
import {ref, inject} from "vue";

const addTodo = inject("addTodo")
let text = ref("")
const add = () => {
  const title = text.value.trim()
  if (!title) {
    alert("输入内容不能为空")
  } else {
    let todo = {"text": title, "finished": false}
    console.log(todo)
    addTodo(todo)
  }
  text.value = ""
}
</script>

<style scoped>

</style>